<?php
/**
* album_cove_template_copy.php    复制专辑模板
*
* @copyright    (C) 2005 - 2010  Zhuayi
* @lastmodify   2012-03-09
* @author       zhuayi
* @QQ			2179942
* @email		renxin1@staff.sina.com.cn
*/

include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;

	if(! security_check::check_refer())
	{
		throw new Exception("来路不明");
	}

}

function get_data()
{
	global $g_cgival, $g_pro, $g_show;
	
	$db = new db_food_album_cover_template();
	
	// 拿到当前站点的site_id
	$site_id = admin::admin_get_user_site_id();
	
	$admin_id = admin::admin_get_login_uid();	// 拿到当前管理员ID
	$admin_name = admin::admin_get_login_user_name();	// 拿到当前管理员用户名

	// 获取河南专辑模板信息
	$henan_template_list = $db->admin_get_food_album_cover_template_list_by_site_id(902,'',2,'',1,1000);

	// 获取当前站点下的专辑模板
	$my_template_list = $db->admin_get_food_album_cover_template_list_by_site_id($site_id,'',2,'',1,1000);


	$my_template_list_tmp = array();

	/* 取模板地址,用来过滤已存在的模板 */
	foreach ($my_template_list as $val)
	{
		$my_template_list_tmp[md5($val['template_image'])] = $val;
	}


	/* 循环插入模板 */
	foreach ($henan_template_list as $val)
	{
		if (!isset($my_template_list_tmp[md5($val['template_image'])]))
		{
			$db->admin_insert_album_cover_template (
													$site_id,
													$val['template_name'],
													$val['template_image'],
													$val['template_small_image'],
													$val['front_status'],
													$admin_id,
													$admin_name
													);
			
		}
	}


	
}

$g_show["error"] = 0;
$g_show["errmsg"] = '';
try
{
	admin_check_login();
 	admin_check_user_priv("foodv2/album/album_cover_template_copy.php");
	
	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	if(isset($_GET['debug']))
		print_r($g_show);
	echo json_encode($g_show);
}

?>